<template>
  <div class="header-container">
    <div class="left">
<!--      <el-icon class="menu-collapse" @click="emit('toggle-collapse')">-->
<!--        <expand v-if="isCollapse" />-->
<!--        <fold v-else />-->
<!--      </el-icon>-->
<!--      <el-breadcrumb separator="/">-->
<!--        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>-->
<!--        <el-breadcrumb-item>当前页面</el-breadcrumb-item>-->
<!--      </el-breadcrumb>-->
    </div>

    <div class="right">
      <el-dropdown>
        <span class="user-info">
          <el-avatar :size="30"><img src="../assets/image/user.png"></el-avatar>
          <span class="username">{{ personname }}</span>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item><a href="/#/profile">profile</a></el-dropdown-item>
            <el-dropdown-item><a @click="logout()">logout</a></el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Fold, Expand } from '@element-plus/icons-vue'
import { defineEmits,reactive } from 'vue'
// 定义组件可以触发的事件
const emit = defineEmits(['toggle-collapse'])

// const isCollapse = ref(false)
// const toggleCollapse = () => {
//   isCollapse.value = !isCollapse.value
// }

import { useStaffStore } from '../stores/staff'
import { useRouter,useRoute} from 'vue-router';
import { setToken} from '../utils/auth'
import { inject } from 'vue'

const currentRoute = useRouter()
const staffStore = useStaffStore()
const personname = staffStore.staff;
const isLoggedIn = inject('isLoggedIn')
function logout() {
  isLoggedIn.value = false;
  localStorage.setItem('isLoggedIn', 'false');
  //设置token
  setToken('');
  staffStore.setToken('');
  staffStore.setStaff(null);
  currentRoute.push('/')
}

</script>

<style scoped>
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
}
.left {
  display: flex;
  align-items: center;
}
.menu-collapse {
  margin-right: 20px;
  font-size: 20px;
  cursor: pointer;
}
.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.username {
  margin-left: 10px;
}
</style>
